*** REPLICATION FILE ***

*** "Electoral cycles of protests and statistical manipulation: 
*** evidence from the COVID-19 pandemic," Democratization
*** Hidekuni Washida
*** October 28, 2024

* Preparation

* Regime type
gen Regime3_bmr = e_boix_regime2019 + 1
recode Regime3_bmr 1=0 if v2x_regime2019==0 & e_boix_regime2019==0
label define regime_label 0 "Closed autocracy" 1 "Electoral autocracy" 2 "Democracy"
label values Regime3_bmr regime_label

* Exclused cases: coup etc
gen post_coup=0
replace post_coup = 1 if ccode==432 & date>=20200818 /* Coup Mali */
replace post_coup = 1 if ccode==436 & date>=20210331 /* Coup Niger */
replace post_coup = 1 if ccode==483 & date>=20210420 /* Coup Chad */
replace post_coup = 1 if ccode==438 & date>=20210905 /* Coup Guinea */
replace post_coup = 1 if ccode==439 & date>=20220124 /* Coup Burkina Faso */
replace post_coup = 1 if ccode==775 & date>=20210201 /* Coup Myanmar */
replace post_coup = 1 if ccode==625 & date>=20211025 /* Coupt Sudan */
replace post_coup = 1 if ccode==436 & date>=20230726 /* Coup Niger */
replace post_coup = 1 if ccode==700 & date>=20210815 /* Afghanistan Taliban */
replace post_coup = 1 if ccode==369 & date>=20220224 /* Ukraine Invaded*/

* Election timing
gen since_ele_main5=0 if since_ele_main!=.
replace since_ele_main5=1 if since_ele_main>=0 & since_ele_main<.2  & since_ele_main!=.
replace since_ele_main5=2 if since_ele_main>=.2 & since_ele_main<.4 & since_ele_main!=.
replace since_ele_main5=3 if since_ele_main>=.4 & since_ele_main<.6 & since_ele_main!=.
replace since_ele_main5=4 if since_ele_main>=.6 & since_ele_main<.8 & since_ele_main!=.
replace since_ele_main5=5 if since_ele_main>=.8 & since_ele_main<1 & since_ele_main!=.
replace since_ele_main5=6 if since_ele_main>=1 & since_ele_main!=.
gen postpone_main=0 if since_ele_main!=.
recode postpone_main 0=1 if since_ele_main>1 & since_ele_main!=.

********************************************************************************

*** Figures 2, 3, 4, 5, 6, and 7; Table 1; 
*** Appendices C3, C4, and C5 (and corresponding Appendices A and B)

* Figure 2
reg ln_new_deaths_per_million i.Regime3_bmr##c.lnexcess_economist_pm i.t_week i.e_regionpol_6C lngdppc if post_coup==0 , cluster(ccode) 
margins, dydx(lnexcess_economist_pm) at(Regime3_bmr=(0 1 2))
marginsplot, horizontal recast(scatter) aspect(.15) ysc(reverse) title("ME of excess mortality on reported mortality", size(Medium)) ytitle("") xtitle("") 
* descriptive statistics
sum ln_new_deaths_per_million i.Regime3_bmr lnexcess_economist_pm lngdppc if e(sample)==1

* Figure 3
// gen m7b_protestriot30 = m7b_protestriot/29.42857
// gen m7b_protestriot30_covid = m7b_protestriot_covid_/29.42857
* Russia
twoway (line since_ele_main  date_t if ccode==365  ,lcolor(red%80) yaxis(1) title("Russia", size(medium)) xline(22298 22700, lwidth(thin) lpattern(shortdash) lcolor(black%80)) text(.99 22299 "Arrest of Navalny", place(e) color(black) size(small)) text(.99 22701 "Invasion of Ukraine", place(e) color(black) size(small)) xtitle("")) || (connected m7b_ln_new_deaths_per_million date_t if ccode== 365, lpattern(shortdash) lcolor(blue) yaxis(2) msymbol(none)) || (connected m7b_lnexcess_economist_pm date_t if ccode==365, lpattern(solid) lcolor(blue) yaxis(2) msymbol(none) ) ||  (bar m7b_protestriot30  date_t if ccode==365, yaxis(1) color(gs10%40)) || (bar m7b_protestriot30_covid date_t if ccode==365  , yaxis(1) color(gs4)), legend(size(small) lab(1 "Electoral proximity") lab (4 "Reported (right)") lab (5 "Excess (right)") lab(2 "Protests&riots") lab(3 "Protests&riots(Covid)")) saving(russia.gph, replace) aspect(.7)
* Honduras
twoway (line since_ele_main date_t if ccode==91 ,lcolor(red%80) yaxis(1) title("Honduras", size(medium)) xline(22612, lwidth(thin) lpattern(shortdash) lcolor(black%80)) text(.99 22615 "Election", place(e) color(black) size(small)) xtitle(""))|| (connected m7b_ln_new_deaths_per_million date_t if  ccode== 91 ,lwidth(medithick) lpattern(shortdash) lcolor(blue) msymbol(none) yaxis(2)) || (connected m7b_lnexcess_economist_pm date_t if ccode==91 ,lwidth(medithick) lpattern(solid) lcolor(blue) msymbol(none) yaxis(2)) ||  (bar m7b_protestriot30 date_t if ccode==91, yaxis(1) color(gs10%40)) || (bar m7b_protestriot30_covid date_t if ccode==91 , yaxis(1) color(gs4)), legend(size(small) lab(1 "Electoral proximity") lab (4 "Reported (right)") lab (5 "Excess (right)") lab(2 "Protests&riots") lab(3 "Protests&riots(Covid)")) saving(honduras.gph, replace) aspect(.7)
graph combine russia.gph honduras.gph

* Figure 4
xtregar ln_new_deaths_per_million i.e_boix_regime2019##i.since_ele_main5##c.lnexcess_economist_pm i.t_week if post_coup==0 & postpone_main==0 & v2x_regime2019!=0, fe 
margins, dydx(lnexcess_economist_pm) at(since_ele_main5=(1(1)5) e_boix_regime2019=(0 1))
marginsplot,  by(e_boix_regime2019) 
* descriptive statistics
sum ln_new_deaths_per_million e_boix_regime2019 i.since_ele_main5 lnexcess_economist_pm if e(sample)==1

* Figure 5
// gen _v2pssunpar = -v2pssunpar 
xtregar ln_new_deaths_per_million i.since_ele_main5##c.lnexcess_economist_pm##c._v2pssunpar i.t_week if post_coup==0 & postpone_main==0 & v2x_regime2019!=0 & e_boix_regime2019==0 , fe 
sum _v2pssunpar if e(sample)==1, detail
margins, dydx(lnexcess_economist_pm) at(since_ele_main5=(1(1)5) _v2pssunpar=( -.818 1.438))
marginsplot 
* descriptive statistics
sum ln_new_deaths_per_million i.since_ele_main5  lnexcess_economist_pm  _v2pssunpar if e(sample)==1

* Table 1
tabstat protestriot protestriot_covid, by(Regime3_bmr) stats(mean)
tabstat ele_main turnover_main, by(Regime3_bmr) stats(sum)

* Figure 6
// gen lm7_protestriot=(l.protestriot + l2.protestriot + l3.protestriot + l4.protestriot + l5.protestriot + l6.protestriot + l7.protestriot)/7
xtnbreg protestriot lm7_protestriot c.e_boix_regime2019##i.since_ele_main5 i.t_week if post_coup==0 & v2x_regime2019!=0 & since_ele_main5!=6, fe
margins,  at(since_ele_main5=(1(1)5) e_boix_regime2019=(0 1)) predict(nu0)
marginsplot, by(e_boix_regime2019) aspect(1) title("") xtitle("Electoral cycles") ytitle("Predicted number of collective actions")
* descriptive statistics
sum protestriot lm7_protestriot e_boix_regime2019 i.since_ele_main5 if e(sample)==1

* Figure 7
// gen dif_excessreport = lnexcess_economist_pm - ln_new_deaths_per_million
// tsegen lm7b_dif_excessreport = rowmean(L(1/7).dif_excessreport)
// label var lm7b_dif_excessreport "Under-reporting"
xtnbreg protestriot_covid lm7b_protestriot_covid lm7b_lnexcess_economist_pm lm7b_dif_excessreport i.t_week if post_coup==0 & v2x_regime2019!=0 & e_boix_regime2019==0 & since_ele_main5!=6, fe
estimates store covidpro_all
coefplot, drop(_cons *ccode *t_week) xline(0) aspect(.2) grid(none)
* descriptive statistics
sum protestriot_covid lm7b_protestriot_covid lm7b_lnexcess_economist_pm lm7b_dif_excessreport if e(sample)==1

********************************************************************************

* Appendix C3-1
// gen gov2_party=( gov2_v2palocoff + gov2_v2paactcom )/2
xtregar ln_new_deaths_per_million i.since_ele_main5##c.lnexcess_economist_pm##c.gov2_party i.t_week if post_coup==0 & postpone_main==0 & v2x_regime2019!=0 & e_boix_regime2019==0 , fe 
sum gov2_party if e(sample)==1, detail
margins, dydx(lnexcess_economist_pm) at(since_ele_main5=(1(1)5) gov2_party=( 1.0425 2.386 ))
marginsplot 

* Appendix C4-1
// tsegen lm31b_lnprotestriot = rowmean(L(1/31).lnprotestriot)
// sum lm31b_lnprotestriot if e(sample)==1 & e_boix_regime2019==0
// sum lm31b_lnprotestriot if e(sample)==1 & e_boix_regime2019==1
// gen std_lm31b_lnprotestriot =(lm31b_lnprotestriot-.47964)/.5154583 if e_boix_regime2019==0
// replace std_lm31b_lnprotestriot = (lm31b_lnprotestriot-.858399)/.8525612 if e_boix_regime==1
logit turnover_main i.e_boix_regime2019 std_lm31b_lnprotestriot  if v2x_regime2019!=0, cluster(e_regionpol_6C)
margins, dydx(std_lm31b_lnprotestriot) at( e_boix_regime2019=(0 1) ) level(90)
marginsplot, horizontal aspect(.1) xline(0) recast(scatter)
margins, dydx(std_lm31b_lnprotestriot) at( e_boix_regime2019=(0 1) ) level(95)
marginsplot, horizontal aspect(.1) xline(0) recast(scatter)
* Appendix C4-2
margins, at(std_lm31b_lnprotestriot=(-1(.5)3.5) e_boix_regime2019=(0 1) )
marginsplot, by(e_boix_regime2019)

* Appendix C5-1
xtnbreg protestriot_covid lm7b_protestriot_covid lm7b_lnexcess_economist_pm i.since_ele_main5##c.lm7b_dif_excessreport i.t_week if post_coup==0 & v2x_regime2019!=0 & e_boix_regime2019==0 & since_ele_main5!=6, fe
coefplot, drop(_cons *ccode *t_week) xline(0)
sum lm7b_dif_excessreport  if e(sample)==1, detail
margins, at(since_ele_main5=(1(1)5) lm7b_dif_excessreport =(.4347815 1.312608)) predict(nu0)
marginsplot, aspect(1) title("") xtitle("Electoral cycles") ytitle("ME of underreporting on collective actions")

********************************************************************************
*** making weekly data 
collapse (sum) new_deaths (mean) v2pssunpar (max) since_ele_main5 postpone_main post_coup e_boix_regime2019 v2x_regime2019, by(country_name ccode t_week)

gen new_deaths_first_digit = real(substr(string(new_deaths , "%15.0g"), 1, 1))

* v2pssunpar
gen v2pssunparD = 0 if v2pssunpar!=.
sum v2pssunpar if e_boix_regime2019==0 & since_ele_main5!=. & post_coup==0 & new_deaths_first_digit>0 & postpone_main!=1 & v2x_regime2019!=0, detail
recode v2pssunparD 0=1 if v2pssunpar>=-.192
